You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

24 lines
941 B

import { defineWrappedResponseHandler } from "#server/utils/handler";
import { R } from "#server/utils/response";
import { resolveAgentIdentity } from "#server/service/agent/identity";
import { getSessionByIdAndUser, getMessagesBySession } from "#server/service/agent/session";
export default defineWrappedResponseHandler(async (event) => {
const identity = await resolveAgentIdentity(event);
const id = getRouterParam(event, "id");
if (!id) {
return R.error("参数无效", null);
}
const session = await getSessionByIdAndUser(id, identity.userId, identity.tempToken);
if (!session) {
return R.error("会话不存在", null);
}
const query = getQuery(event);
const before = query.before ? Number(query.before) : undefined;
const limit = Number(query.limit) || 50;
const messages = await getMessagesBySession(id, { before, limit });
return R.success({ messages, hasMore: messages.length === limit });
});